package com.yanqu.road.server.cmd.banquet.crossBanquet;

import com.yanqu.road.entity.banquet.UserCrossBanquetData;
import com.yanqu.road.entity.enums.eBanquetInfoType;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_BANQUET_CROSS_GET_POP_REWARD, desc = "获取本服盛宴的人气礼")
public class GetBanquetPopRewardCmd extends AbstractCommand {

	private String banquetId;
	private int rewardId;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BanquetProto.BanquetGetPopRewardReq reqMsg = BanquetProto.BanquetGetPopRewardReq.parseFrom(packet.getBytes());
		banquetId = reqMsg.getBanquetId();
		rewardId = reqMsg.getRewardId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		UserCrossBanquetData banquet = CrossBanquetMgr.getBanquet(banquetId);
		if(banquet != null && banquet.getType() == eBanquetInfoType.CrossMogulBirthdayBanquet.getValue()){
			ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
			return;
		}
		ret = player.getModule(BanquetModule.class).getCrossBanquetPopReward(banquetId,rewardId);
		if (banquet == null || CrossBanquetMgr.isBanquetOver(banquet.getBanquetId())) {
			return;
		}
		player.getModule(BanquetModule.class).crossBanquetPopRewardSync(banquet);

	}

	@Override
	public void sendData(GamePlayer player) {
		BanquetProto.BanquetGetPopRewardResp.Builder respMsg = BanquetProto.BanquetGetPopRewardResp.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BANQUET_CROSS_GET_POP_REWARD, respMsg);
	}
}
